package lovo.practice_7_14.frame;

import lovo.Util.Util;
import lovo.practice_7_14.pojo.UserDO;

import javax.swing.*;
import java.awt.*;
import java.util.List;


public class J189_7_14 extends JFrame {
    private int i;
    private TransPanel transPanel = new TransPanel(this);
    private LoginPanel loginPanel = new LoginPanel(this);
    private MunePanel munePanel = new MunePanel(this);
    private ScanPanel scanPanel = new ScanPanel(this);
    private SetPwdPanel setPwdPanel = new SetPwdPanel(this);
    private UserDO users;


    public LoginPanel getLoginPanel() {
        return loginPanel;
    }

    public MunePanel getMunePanel() {
        return munePanel;
    }

    public ScanPanel getScanPanel() {
        return scanPanel;
    }

    public SavePanel getSavePanel() {
        return savePanel;
    }

    public GetPanel getGetPanel() {
        return getPanel;
    }

    public FindPanel getFindPanel() {
        return findPanel;
    }

    public UserDO getUsers() {
        return users;
    }

    public void setUsers(UserDO users) {
        this.users = users;
    }

    private SavePanel savePanel = new SavePanel(this);
    private GetPanel getPanel = new GetPanel(this);
    private FindPanel findPanel = new FindPanel(this);
    private List<UserDO> listusers; //设置了一个存放用户对象的集合

    public int getI() {
        return i;
    }

    public void setI(int i) {
        this.i = i;
    }

    public List<UserDO> getListusers() {
        return listusers;
    }

    public void setListusers(List<UserDO> listusers) {
        this.listusers = listusers;
    }

    private Image ImageTitle = Util.getimages("/Images/微信图片_20220705124452.jpg");
    private Image ImageBack = Util.getimages("/Images/background.jpg");

    private CardLayout cardLayout = new CardLayout();


//    /**
//     * 创建连接 t_atm
//     *
//     * @return
//     */
//    public Connection getConnection() {
//        // 1. 加载驱动
//        Connection con = null;
//        try {
//            Class.forName("com.mysql.cj.jdbc.Driver");
//            // 2. 创建连接
//            con = DriverManager.getConnection(
//                    "jdbc:mysql://localhost:3306/j189?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT",
//                    "root", "0201");
//
//        } catch (ClassNotFoundException | SQLException e) {
//            e.printStackTrace();
//        }
//        return con;
//    }
//
//    /**
//     * 将数据库t_atm的数据转到一个装着数据类型（用户类型）的集合List里去
//     *
//     * @return
//     */
//    public List query() {
//        //1创建连接
//        Connection con = getConnection();
//        Statement statement = null;
//        ResultSet rs = null;
//        List listusers1 = new ArrayList();
//        try {
//            //2获取执行SQL语句的对象
//            statement = con.createStatement();
//            String sql = "select * from t_atm";
//            //3 执行SQL并返回结果集
//            rs = statement.executeQuery(sql);
//            while (rs.next()) {
//                UserDO user = new UserDO();
//                user.setAccount(rs.getString("a_account"));
//                user.setPwd(rs.getString("a_password"));
//                user.setBalance(rs.getDouble("a_balance"));
//                listusers1.add(user);
//            }
//        } catch (SQLException throwables) {
//            throwables.printStackTrace();
//        } finally {
//            if (statement != null) {
//                try {
//                    statement.close();
//                } catch (SQLException throwables) {
//                    throwables.printStackTrace();
//                }
//            }
//            if (rs != null) {
//                try {
//                    rs.close();
//                } catch (SQLException throwables) {
//                    throwables.printStackTrace();
//                }
//            }
//            if (con != null) {
//                try {
//                    con.close();
//                } catch (SQLException throwables) {
//                    throwables.printStackTrace();
//                }
//            }
//
//        }
//        return listusers1;
//    }


    public J189_7_14() {
        //1 设置背景图
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(ImageBack, 0, 0, 1024, 768, this);
            }
        });

        this.setLayout(cardLayout);

        // 2 设置登录按钮
        this.add("login", loginPanel);
        //  3 设置菜单card
        this.add("mune", munePanel);
        //4 存钱card
        this.add("save", savePanel);
        //5 取钱card
        this.add("get", getPanel);
        // 6 查询card
        this.add("find", findPanel);
        // 输入账号密码card
        this.add("scan", scanPanel);
        // 7 转账card
        this.add("trans", transPanel);
        // 8 改密码card
        this.add("setPwd", setPwdPanel);
        //0 初始化

//        setListusers(query()); //将用户数据写进用户集合里
        this.setSize(1024, 768);
        this.setTitle("银行管理系统");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setIconImage(ImageTitle);
        this.setVisible(true);
    }

    // 实现 切换卡片的方法
    public void switchPanel(String name) {
        cardLayout.show(this.getContentPane(), name);
    }

//    public void setMoney() {
////        getFindPanel().getJLabelFind().setText(getUsers().getBalance() + "");
//
//    }


    public static void main(String[] args) {
        J189_7_14 atm = new J189_7_14();
    }
}
